<?php
// 角色模块
class RoleAction extends CommonAction {
    function index(){
        $role=D("Role");
        import("ORG.Util.Page");// 导入分页类
        $count=$role->count();
        $Page= new Page($count,10);// 实例化分页类 传入总记录数和每页显示的记录数
        $Page->setConfigArray(array('header'=>'组角色','prev'=>'<input type="button" value="<<<">','next'=>'<input type="button" value=">>>">','first'=>'首页','last'=>'尾页','theme'=>' %totalRow% %header% %nowPage%/%totalPage% 页   %first% %prePage% %upPage%   <span style="color: red;background-color: #7fffd4;">%linkPage%</span>   %downPage% %nextPage% %end%'));
        $show=$Page->show();//分页显示输出
        $list=$role->limit($Page->firstRow.",".$Page->listRows)->select();
        $this->assign("list",$list);
        $this->assign('page',$show);// 赋值分页输出
        $this->display();
    }


    function delete(){
        if(!empty($_GET['id'])){
             $role=M("Role");
            $role->delete($_GET['id']);
        }
        $this->redirect("index");
    }


    function  add(){
        $role=M("Role");
        $list=$role->select();
        $this->assign("list",$list);
        $this->display();
    }


    function insert(){
        $role=D("Role");
        if($role->create()){
            $role->add();
        }
        $this->redirect("index");
    }


    function modify(){
        if(!empty($_GET['id'])){
            $role=M("Role");
            $list=$role->select();
            $this->assign("list",$list);
            $data["id"]=$_GET['id'];
            $roleObj=$role->where($data)->find();
            $this->assign("role",$roleObj);
        }
        $this->display();
    }


    function update(){
        $role=D("Role");
        if($role->create()){
            $role->save();
        }
        $this->redirect("index");
    }
}